//
//  MainVC.m
//  Book
//
//  Created by zhiyou on 16-3-23.
//  Copyright (c) 2016年 陈凯. All rights reserved.
//

#import "MainVC.h"
#import "ASIHTTPRequest.h"
#import "XMlParser.h"
#import"UIImageView+WebCache.h"
#import "Masonry.h"
#import "MyTable.h"
#import "Book.h"
#import "Tools.h"
#import "Custom.h"
#import "DetailVC.h"
@interface MainVC ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation MainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title=@"书库";
         [Custom json];
    _KindArray=[[NSArray alloc]initWithObjects:@"玄幻魔法",@"武侠修真",@"都市异能",@"历史军事",@"科幻竞技", nil];
   
    NSMutableArray*array=[MyTable selectAllBook];
    _dataArray=[Custom SetWithDataArray:array];
    
    _tableview.delegate=self;
    _tableview.dataSource=self;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 
         return 4;
    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
               }
    
    Book*book=_dataArray[indexPath.section][indexPath.row];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:book.ImageName] placeholderImage:[UIImage imageNamed:@"place"]];
    cell.textLabel.text=book.bookname;
     cell.detailTextLabel.text=book.detail;
    cell.detailTextLabel.font=[UIFont systemFontOfSize:13];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
          return 44;
    
}
#pragma mark---------tableview的区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  
        return 30;
    
}
#pragma mark---------tableview的区头视图
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
      UIView*headerview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 30)];
    [_tableview addSubview:headerview];
    UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.titleLabel.font=[UIFont systemFontOfSize:12];
    button.backgroundColor=[UIColor cyanColor];
    [button setTitle:_KindArray[section] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.frame=CGRectMake(0, 0, self.view.bounds.size.width, 30);
    [headerview addSubview:button];
    return headerview;
    
}
#pragma mark----------选中某一行的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DetailVC*vc=[[DetailVC alloc]init];
    vc.bk=_dataArray[indexPath.section][indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
